package com.ywjt.platformbusiness.store.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.ywjt.platformbusiness.EventBusBean;
import com.ywjt.platformbusiness.R;
import com.ywjt.platformbusiness.base.BaseActivity;
import com.ywjt.platformbusiness.common.UserData;
import com.ywjt.platformbusiness.constants.Constants;
import com.ywjt.platformbusiness.constants.UrlConstants;
import com.ywjt.platformbusiness.http.HttpRequest;
import com.ywjt.platformbusiness.http.HttpStringCallBack;
import com.ywjt.platformbusiness.store.adapter.StoreOrderListAdapter;
import com.ywjt.platformbusiness.store.adapter.WeekThisYearPAdapter;
import com.ywjt.platformbusiness.store.model.WeekThisYear;
import com.ywjt.platformbusiness.store.order.activity.StoreOrderFinish;
import com.ywjt.platformbusiness.store.order.activity.StoreOrderPostSale;
import com.ywjt.platformbusiness.store.order.activity.StoreOrderUnConfirm;
import com.ywjt.platformbusiness.store.order.activity.StoreOrderUnPay;
import com.ywjt.platformbusiness.store.order.activity.StoreOrderUnSend;
import com.ywjt.platformbusiness.store.order.model.StoreOrderListModel;
import com.ywjt.platformbusiness.util.JsonUtils;
import com.ywjt.platformbusiness.util.SoftKeyboardUtils;
import com.ywjt.platformbusiness.widget.CenterDialogEdit;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ActivityWeekThisYear extends BaseActivity implements View.OnClickListener {
    private WeekThisYearPAdapter adapter;
    private RecyclerView rcView;


    public static void actionStart(Context context) {
        Intent intent = new Intent(context, ActivityWeekThisYear.class);
        context.startActivity(intent);
    }

    //获取数据
    public void getData(){
        new HttpRequest(ActivityWeekThisYear.this).doGet(UrlConstants.merchant_getWeekByYearMonth, null, new HttpStringCallBack() {
            @RequiresApi(api = Build.VERSION_CODES.M)
            @Override
            public void onSuccess(Object result) {
                String datas = result.toString();
                JSONObject jsonObject = null;
                try {
                    jsonObject = new JSONObject(datas);
                    String message = jsonObject.getString("message");
                    Boolean success = jsonObject.getBoolean("success");
                    if (success) {
                        Object obj = JsonUtils.fromJson(result.toString(), WeekThisYear.class);
                        if (obj instanceof WeekThisYear) {
                            WeekThisYear model = (WeekThisYear) obj;
                            if (model.getResult().size() > 0) {
                                rcView.setVisibility(View.VISIBLE);
                                adapter = new WeekThisYearPAdapter(model.getResult());
                                rcView.setLayoutManager(new LinearLayoutManager(ActivityWeekThisYear.this));
                                rcView.setAdapter(adapter);

                                adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                                    @Override
                                    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                                    }
                                });
                            }
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(int code, String msg) {
            }
        });
    }


    @Override
    protected void init(Bundle savedInstanceState) {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.activity_week_thisyear;
    }

    public void initView(){
        if(!EventBus.getDefault().isRegistered(this)){//加上判断
            EventBus.getDefault().register(this);
        }
        setTitleText("请选择时间");
        rcView=findViewById(R.id.rcCommon);
        getData();
    }

    @Override
    protected void initData() {

    }

    /**
     * 获取要使用的标题栏样式(此函数由子类重写)
     *
     * @return
     */
    @Override
    protected int getTitleBarType() {
        return 0;
    }


    @Override
    public void onClick(View v) {

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void wxPaySuccess(EventBusBean eventBus){
        switch (eventBus.getCode()){
            case 101:
                Intent intent = new Intent();
                intent.putExtra("starTime",eventBus.getMsg());
                setResult(RESULT_OK, intent);
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(EventBus.getDefault().isRegistered(this)){//加上判断
            EventBus.getDefault().unregister(this);
        }
    }
}
